package es.ucm.is.www.GUI.client.units;

import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;

public class UnitsBeingConstructed extends Composite{

	private UnitNoTime unit;
	private UnitNoTime tank;
	private PanelUnits padre;
	private CaptionPanel cPanel;
	private Grid hPanel;
	
	
	public UnitsBeingConstructed(PanelUnits padre){

		hPanel = new Grid(1,2);
		cPanel = new CaptionPanel();
		cPanel.setCaptionHTML("<style= \"font-family: \"lucida console\"; font-size: 15px; color: red;>Construccion</style>");
		this.padre = padre;
		cPanel.setStyleName("panelConstruccion");
		cPanel.add(hPanel);
		initWidget(cPanel);
		cPanel.setHeight("170px");
	}
	
	

	public void putUnitBeingConstructed(UnitNoTime b){
		//this.unit = b;
		//b.setState(UnitNoTime.IS_BEING_CONSTRUCTED);
		setUnitAndTimeAndStart(b,b.getUnidad().getInitialTime());
		/*if(b.getUnidad().getIdUnit()<=3){
			this.unit = b;
			hPanel.setWidget(0,0,b);
		}else{
			this.tank = b;
			hPanel.setWidget(0,1,b);
		}*/
	}
	
	public void setUnit(UnitNoTime u){
		this.unit = u;
		hPanel.setWidget(0,0,u);
	}
	
	public void setUnitAndTimeAndStart(UnitNoTime u,float time){
		
		int time2 = (int)time;
		
		if(u.getUnidad().getIdUnit()<=3){
			this.unit = u;
			unit.ponerTiempo(time2);
			unit.start();
			hPanel.setWidget(0,0,unit);
		}else{
			this.tank = u;
			tank.ponerTiempo(time2);
			tank.start();
			hPanel.setWidget(0,1,tank);
		}
	}
	
	public void setTimeAndStart(int time){
		unit.ponerTiempo(time);
		unit.start();
	}
	
	public UnitNoTime getUnit(){
		return unit;
	}
	
	public boolean isUnitConstructing(){
		return hPanel.getWidget(0,0)!=null;
	}
	
	public boolean isTankConstructing(){
		return hPanel.getWidget(0,1)!=null;
	}

	public boolean isBuilding(){
		
		return isUnitConstructing() || isTankConstructing();
	}
	
	public UnitNoTime getTank() {
		return tank;
	}

	public void setTank(UnitNoTime tank) {
		this.tank = tank;
	}
	
	public PanelUnits getPadre() {
		return padre;
	}
	
	public void remove(UnitBeingConstructed u) {
		hPanel.remove(u);
	}
}
